<template>
  <el-select
      :loading="loading"
      clearable
      filterable
      placeholder="请选择巡查分类"
      class="ele-fluid"
      :value="value"
      @change="change">
    <el-option v-for="item in option" :key="item.id" :label="item.name" :value=item.id />
  </el-select>
</template>

<script>
export default {
  props: {
    value: String,
    model_type:String
  },
  model: {
    prop: 'value',
    event: 'change',
  },
  data: function () {
    return {
      option: [],
      loading: false,
    };
  },
  mounted() {
    this.loading = true
    this.$http.post('/abnormal/index?page=1&limit=999&model_type='+this.model_type).then(res => {
      if (res.data.code === 0) {
        this.option = []
        for (let i in res.data.data) {
          this.option.push({
            name: res.data.data[i]['name'],
            id: res.data.data[i]['id'].toString()
          })
        }
      } else {
        this.$message.error(res.data.msg);
      }
      this.loading = false
    }).catch(e => {
      this.loading = false
      this.$message.error(e.message);
    });
  },
  methods: {
    change(val) {
      this.$emit('change', val);
    }
  },
};
</script>